sql.DB is a connection pool, not a single connection. Configure pool size, idle connections, and connection lifetime to match your database's max_connections and service traffic patterns.
MaxOpenConns: set to (Postgres max_connections / number_of_service_instances) - some buffer
MaxIdleConns: should be less than MaxOpenConns; keep commonly-needed connections alive
ConnMaxLifetime: prevents stale connections after DB restarts or network disruptions
Always use QueryContext, ExecContext, BeginTx — never the non-context variants in production
For high-performance workloads, consider pgxpool from jackc/pgx which has better pool control